package com.zombie.ui;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Event;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.zombie.Constants;
import com.zombie.ZombieGame;
import com.zombie.util.state.transition.FadeInTransition;
import com.zombie.util.state.transition.FadeOutTransition;

public class OptionsUI extends UI implements EventListener{

	public Label fpsLabel;
	public Label errorLabel;
	public Button back,save,options,exit;
//	public TextField passwordTextField;
//	public TextField loginTextField;
	public Window window;
	public Actor current;
	
	public void init(){
		skin = new Skin(Gdx.files.internal("data/ui/uiskin.json"));

		back = new TextButton("Back", skin);
		back.setColor(Color.RED);
		back.setBounds(32, 150, 64, 24);
		back.addListener(this);
		save = new TextButton("Save", skin);
		save.setColor(Color.RED);
		save.setBounds(32+64+32, 150, 64, 24);
		save.addListener(this);
		
		
//		Label passwordLabel = new Label("Password: ", skin);
//		passwordTextField = new TextField("", skin);
//		passwordTextField.setMessageText("password");
//		passwordTextField.setPasswordCharacter('*');
//		passwordTextField.setPasswordMode(true);
//
//		Label loginLabel = new Label("Login: ", skin);
//		loginTextField = new TextField("", skin);
//		loginTextField.setMessageText("login");
//
//		errorLabel = new Label("", skin);
//		errorLabel.setColor(Color.RED);
		Slider slide1 = new Slider(0f, 100f, 1f, false, skin);
		CheckBox soundOnOff = new CheckBox("", skin);
		
		window = new Window("Options", skin);

		window.setPosition(32,
				Gdx.graphics.getHeight() / 2 - window.getHeight() / 2+100);
//		window.setSize(400, 400);
		window.setMovable(false);
//		window.defaults().spaceBottom(10);
//		window.defaults().spaceTop(10);
//		
		window.defaults().space(10);
//		window.defaults().pad(5);
//		window.defaults().minSize(16);
//		window.row().fill().expandX();
		window.add(new Label("Sound",skin)).colspan(2);
		window.add(new Label("Graphics",skin)).colspan(2);
		window.add(new Label("Control",skin)).colspan(2);		
		window.row();
		window.add(new Label("Volume",skin));
		window.add(slide1).expandY();
		window.row();
		window.add(new Label("Sound",skin));
		window.add(soundOnOff).expandY();
		window.row();
//		window.add(button).colspan(4);
		window.debug();
		window.pack();

	}

	@Override
	public void add(Stage stage) {
		stage.addActor(back);
		stage.addActor(save);
		stage.addActor(window);
	}

	@Override
	public boolean handle(Event event) {
		if (event instanceof ChangeEvent){
			if (event.getListenerActor() == back){
				ZombieGame.getInstance().enterState(Constants.STATE_MENU, new FadeOutTransition(Color.RED), new FadeInTransition(Color.RED));
			}
		}
		return false;
	}

	public void onEnter() {

	}
	
	
}
